import apiClient from "../http";
import {AxiosResponse} from 'axios';
import {getChatOrNew, getChats, newMultiChat, deleteChat} from "../routes"
import {ChatsListResponse} from "../models/response/ChatsListResponse";
import {ChatsListItem} from "../models/response/ChatsListItem";
import ChatRequest from "../models/request/ChatRequest";
import {DeleteChatResponse} from "../models/response/Other/DeleteChatResponse";

export default class ChatService {
    public static async getChatsList(): Promise<AxiosResponse<ChatsListResponse>> {
        return apiClient.get<ChatsListResponse>(getChats());
    }

    public static async getDialogOrNew(otherUserId: string): Promise<AxiosResponse<ChatsListItem>> {
        return apiClient.get<ChatsListItem>(getChatOrNew(otherUserId));
    }

    public static async getNewMultiDialog(newDialog: ChatRequest): Promise<AxiosResponse<ChatsListItem>> {
        return apiClient.post<ChatsListItem>(newMultiChat(), newDialog);
    }

    public static async deleteChat(chatId: string): Promise<AxiosResponse<DeleteChatResponse>> {
        return apiClient.delete<DeleteChatResponse>(deleteChat(chatId.toString()));
    }
}